package xyz.bali16.module.netdisk.model.vo;

import org.mapstruct.*;
import org.mapstruct.factory.Mappers;
import xyz.bali16.module.netdisk.entity.UploadFile;

import java.util.List;

/**
 * @author bali2 on 2/11/2021.
 * @version 1.0
 */

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UploadFileFileVoConvert {
    UploadFileFileVoConvert INSTANCE = Mappers.getMapper(UploadFileFileVoConvert.class);
    @Named("toVo")
    @Mapping( target = "relativeUrl", expression = "java(child.getPath() + \"/\" + child.getUUID()+child.getSuffix())")
    FileVo map(UploadFile child);
    @IterableMapping(qualifiedByName = "toVo")
    List<FileVo> map(List<UploadFile> uploadFile);
}

//    Using @AfterMapping or @BeforeMapping
//@Mapper
//public interface BookMapper {
//
//    BookMapper INSTANCE = Mappers.getMapper(BookMapper.class);
//
//
//    @Mapping(target = "author", ignore = true)
//    BookDTO toDTO(Book book);
//
//    @AfterMapping
//    default void setBookAuthor(@MappingTarget BookDTO bookDTO, Book book) {
//        Author author = book.getAuthor();
//        bookDTO.setAuthor(author.getFirstName() + " " + author.getLastName());
//    }
//
//}